###使用贝叶斯调参方法最大化目标函数

class model_leather():
    def __init__(self, data, N, leakage_rate=0.1, rho=1, sparsity=2, T_train=8000, T_predict=1000, T_discard=400,
                 eta=1e-4, seed=2050):
        self.data = data

        self.N = N  # reservoir size 库的大小

        self.leakage_rate = leakage_rate  # 泄漏率

        self.rho = rho  # spectral radius 谱半径

        self.sparsity = sparsity  # average degree 平均度       sparsity：稀疏性

        self.T_train = T_train  # training steps

        self.T_predict = T_predict  # prediction steps

        self.T_discard = T_discard  # discard first T_discard steps  discard：丢弃

        self.eta = eta  # regularization constant 正则化常数

        self.seed = seed  # random seed


def objective(trial):
    # 2. 使用trial对象建议超参数取值
    leakage_rate = trial.suggest_float('leakage_rate', 0.01, 0.02)
    rho = trial.suggest_float('rho', 0.95, 1)
    sparsity = trial.suggest_float('sparsity', 2, 4)
    data = loadData('mackey_glass_t17.npy')

    esn = model_leather(data, 1000, leakage_rate,rho,sparsity,8000, 1000, 400, 1e-4, 2050)
    esn.initialize()
    esn.train()
    esn.predict()
    return esn.rmse_error()